<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>0.5px边框</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        .root {
            margin-left: 20px;
            height: 100%;
        }

        .box {
            border: 1px solid #000;
            width: 100px;
            height: 100px;
        }

        .hr {
            background-color: #000;
            width: 300px;
        }

        .txt {
            margin: 5px 0;
        }

        .h1 {
            height: 1px;
        }

        .half {
            height: 0.5px;
        }

        .hr.scale-half {
            height: 1px;
            transform: scaleY(0.5);
            /* transform-origin: 50% 100%; */
        }
        .shu-scale-half {
            width: 1px;
            height: 70px;
            transform: scaleX(0.5); 
        }

        .hr.gradient {
            height: 1px;
            background: linear-gradient(0deg, #fff, #000);
        }

        .hr.boxshadow {
            height: 1px;
            background: none;
            box-shadow: 0 0.5px 0 #000;
        }

        .container {
            width: 500px;
        }

        .border-all {
            position: relative;
            padding: 10px;
        }


        .border-all:after {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            /* z-index: -1; */
            width: 200%;
            height: 200%;
            border: 1px solid #000;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            /* -webkit-transform: scale(.5, .5); */
            transform: scale(.5, .5);
        }
    </style>
</head>

<body>
    <div class="root">
        <div class="box"></div>
        <div class="container">

            <h3>拓展：四周全是0.5px的线条的话</h3>
            <div class="border-all"> 
                大致原理是：通过CSS3插入一个伪元素，该元素宽度为父级2倍，高度为1px，然后通过css3缩放将其缩小一倍，从未实现一个0.5px的边框。
            </div>
        </div>
        <div class="txt">1px</div>
        <p class="hr h1"></p>
        <div class="txt">直接设置0.5px</div>
        <p class="hr half"></p>
        <div class="txt">1px+scaleY(0.5) 0.5px</div>
        <p class="hr scale-half"></p>
        <p class="txt">linear-gradient(0deg, #fff, #000)</p>
        <p class="hr gradient"></p>
        <p class="txt">box-shadow: 0 0.5px 0 #000</p>
        <div class="hr boxshadow"></div>
        <div class="txt">竖线1px+scaleY(0.5)</div>
        <p class="hr shu-scale-half"></p>
    </div>

</body>

</html>